/*
 * @Descripttion: null
 * @Author: lcx
 * @version: v01
 * @Date: 2023-10-21 14:39:34
 * @LastEditors: lcx
 * @LastEditTime: 2023-10-21 18:51:03
 */

abstract class Mediator {
    public abstract void sendMessage(String message,Colleague colleague);
}

class Colleague {
    protected Mediator mediator;

    void sendMessage(String message) {
        System.out.println("message:"+ message);
    }
}

class ConcreteMediator extends Mediator {
    private Colleague1 colleague1;
    private Colleague2 colleague2;

    void ConcreteColleague1(Colleague1 colleague1) {
        this.colleague1 = colleague1;
    }

    void ConcreteColleague2(Colleague2 colleague1) {
        this.colleague2 = colleague1;
    }

    public void sendMessage(String message, Colleague colleague) {
        if (colleague == colleague1) {
           
            System.out.println("colleague1 to colleague2 : "+ message);
            colleague2.Notify("colleague2 rec");
        }
        else
        {
            
            System.out.println("colleague2 to colleague1 : "+ message);
            colleague1.Notify("colleague1 rec");
        }
        
    }
}

class Colleague1 extends Colleague {
    Colleague1(Mediator mediator) {
        this.mediator = mediator;
    }

    void sendMessage(String message) {
        mediator.sendMessage("colleague1", this);
    }
        void Notify(String String) {
        System.out.println("Colleague1: " + String);
    }
}

class Colleague2 extends Colleague {
    Colleague2(Mediator mediator) {
        this.mediator = mediator;
    }

    void sendMessage(String message) {
        mediator.sendMessage("colleague2", this);
    }
    
    void Notify(String String) {
        System.out.println("Colleague2: " + String);
    }
    
}

class test {
    public static void main(String[] args) {
        ConcreteMediator mediator = new ConcreteMediator();
        
        Colleague1 concreteColleague1 = new Colleague1(mediator);
        Colleague2 concreteColleague2 = new Colleague2(mediator);

        mediator.ConcreteColleague1(concreteColleague1);
        mediator.ConcreteColleague2(concreteColleague2);

        mediator.sendMessage("hello",concreteColleague1);
        mediator.sendMessage("reply hello",concreteColleague2);
    }



}